home *** CD-ROM | disk | FTP | other *** search
- Path: comsearch.com!tnasca
- From: Thuan Nguyen <thnguyen@comsearch.com>
- Newsgroups: comp.lang.c++
- Subject: virtual function in template class
- Date: 16 Jan 1996 23:01:17 GMT
- Organization: ComSearch, Inc
- Message-ID: <4dhant$gj8@gateway.comsearch.com>
- NNTP-Posting-Host: arcturus.comsearch.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.1N (X11; I; SunOS 4.1.4 sun4c)
- X-URL: news:comp.lang.c++
-
- Hi all, I have a question. Can I have virtual function in template class. My
- template class definition is as follows:
-
- template <class T>
- class Mine
- {
- public:
- void compare_data(T & );
- virtual T * build_data() {}
- ....
- }
-
- class first_data: public Mine<myDataType1>
- {
- public:
- myDataType1 * build_data();
- ....
- }
-
- class second_data : public Mine<myDataType2>
- {
- public:
- myDataType2 * build_data();
- ....
- }
-
- template< class T>
- void Mine<T>::compare_data(T & newData)
- {
- ....
- T * oldData = build_data();
- if ( newData == *oldData) return TRUE;
- ....
- }
-
- eventhough function compare data implementation is in template class Mine. It
- would never be called from there. It will be called only from either class
- first_data or second_data in run time. At that time virtual build_data should
- have been resolved.
-
- I have a lots of problem with this including implecit declaration of build_data
-
- Thanks
-
-